﻿<ctrl:WindowExt x:Class="WickedFlame.VecDraw.MainGui"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:t="clr-namespace:WickedFlame.VecDraw"
    xmlns:document="clr-namespace:WickedFlame.Util;assembly=VecDraw.Util"
    xmlns:uc="clr-namespace:WickedFlame.Util.Controls;assembly=VecDraw.Util"
    xmlns:cmds="clr-namespace:WickedFlame.VecDraw.VecApp"
    xmlns:dialog="clr-namespace:WickedFlame.VecDraw.Dialog"
    xmlns:ctrl="clr-namespace:WickedFlame.VecDraw.Base.Controls;assembly=VecDraw.Base"
    xmlns:core="clr-namespace:WickedFlame.Core;assembly=VecDraw.Core"
    xmlns:v="clr-namespace:WickedFlame.VecDraw.Views"
             xmlns:fac="clr-namespace:WickedFlame.VecDraw.viewmodels.factories"
             xmlns:vm="clr-namespace:WickedFlame.VecDraw.Base.mvvm.factory;assembly=VecDraw.Base"
             vm:ViewModelLoader.FactoryType="{x:Type fac:MainWindowModelFactory}"
    x:Name="ThisWindow"
    Title="VecDraw" Height="700" Width="900" Icon="Images/VD.ico" Loaded="OnLoaded" Closing="OnClosing" Focusable="True" >
    
    <Window.CommandBindings>
        <!--<CommandBinding Command="ApplicationCommands.SelectAll" CanExecute="CommandCanExecute" Executed="CommandExecuted" />-->
        <!--<CommandBinding Command="ApplicationCommands.Delete" CanExecute="CommandCanExecute" Executed="CommandExecuted" />-->
        
        <!--<CommandBinding Command="cmds:MainMenuCustomCommands.RedoCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />-->
        <!--<CommandBinding Command="cmds:MainMenuCustomCommands.UndoCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />-->
        <!--<CommandBinding Command="cmds:MainMenuCustomCommands.PasteCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />-->
        <!--<CommandBinding Command="cmds:MainMenuCustomCommands.CopyCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />-->
        <!--<CommandBinding Command="cmds:MainMenuCustomCommands.CutCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />-->
        <!--<CommandBinding Command="cmds:MainMenuCustomCommands.UnselectAll" CanExecute="CommandCanExecute" Executed="CommandExecuted" />-->
        <!--<CommandBinding Command="cmds:MainMenuCustomCommands.ZoomIn" CanExecute="CommandCanExecute" Executed="CommandExecuted" />-->
        <!--<CommandBinding Command="cmds:MainMenuCustomCommands.ZoomOut" CanExecute="CommandCanExecute" Executed="CommandExecuted" />-->
        <!--<CommandBinding Command="cmds:MainMenuCustomCommands.SaveCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />-->
        <!--<CommandBinding Command="cmds:MainMenuCustomCommands.SaveAsCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />-->
        <!--<CommandBinding Command="cmds:MainMenuCustomCommands.NewCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />-->
        <CommandBinding Command="cmds:MainMenuCustomCommands.ToPolygonCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />
        <CommandBinding Command="cmds:MainMenuCustomCommands.CombineImagesCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />
        <CommandBinding Command="cmds:MainMenuCustomCommands.ToImageCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />
        <!--<CommandBinding Command="cmds:MainMenuCustomCommands.OpenCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />-->
        <CommandBinding Command="cmds:MainMenuCustomCommands.ExitCommand" CanExecute="CommandCanExecute" Executed="CommandExecuted" />
        
        <!-- OptionCommands-->
        <!--<CommandBinding Command="cmds:MainMenuCustomCommands.SnapToTrackerCommand" CanExecute="CommandCanExecute" Executed="OptionCommandExecuted" />-->
        
        <CommandBinding Command="cmds:ShapeCommands.CloseShape" CanExecute="ShapeCommandCanExecute" Executed="ShapeCommandExecuted" />
        <CommandBinding Command="cmds:ShapeCommands.CombineShapesCommand" CanExecute="ShapeCommandCanExecute" Executed="ShapeCommandExecuted" />
        
    </Window.CommandBindings>

    <Window.Resources>
        
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Resources/ToolDataTemplates.xaml" />
                <ResourceDictionary Source="/Resources/MainWindowTemplate.xaml" />
                <ResourceDictionary>
                    
                    <Image x:Key="New" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.New.ico" Height="16" Width="16" />
                    <!--Images/Document.ico-->
                    <Image x:Key="Undo" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.Undo.ico" Height="16" Width="16" />
                    <Image x:Key="Redo" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.Redo.ico" Height="16" Width="16" />
                    <Image x:Key="Save" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.Save.png" Height="16" Width="16" />
                    <!--Images/Save.ico-->
                    <Image x:Key="Open" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.Folder.Open.png" Height="16" Width="16" />
                    <!--Images/Open.ico-->
                    <Image x:Key="SaveAs" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.SaveAs.png" Height="16" Width="16" />
                    <Image x:Key="Minus" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.Minus.png" Height="16" Width="16" />
                    <Image x:Key="Plus" Source="/VecDraw.Resources;component/Images/VecDraw.Icon.Plus.png" Height="16" Width="16" />

                    <LinearGradientBrush x:Key="MainHeaderBrush" StartPoint="0,0" EndPoint="0,1">
                        <LinearGradientBrush.GradientStops>
                            <GradientStop Color="#777777" Offset="0"/>
                            <GradientStop Color="#5A5A5A" Offset="1"/>
                        </LinearGradientBrush.GradientStops>
                    </LinearGradientBrush>

                    <LinearGradientBrush x:Key="HeaderBrush" StartPoint="0,0" EndPoint="0,1">
                        <GradientStop Offset="0.0" Color="#484848" />
                        <GradientStop Offset="1.0" Color="#282828" />
                    </LinearGradientBrush>

                    <LinearGradientBrush x:Key="InvertedHeaderBrush" StartPoint="0,0" EndPoint="0,1">
                        <GradientStop Offset="0.0" Color="#282828" />
                        <GradientStop Offset="1.0" Color="#484848" />
                    </LinearGradientBrush>

                    <LinearGradientBrush x:Key="GradientHeaderBrush" StartPoint="0,0" EndPoint="0,1">
                        <GradientStop Offset="0.0" Color="#505050" />
                        <GradientStop Offset="1.0" Color="#282828" />
                    </LinearGradientBrush>

                    <LinearGradientBrush x:Key="VerticalSpliterBrush"
                         StartPoint="1,0"
                         EndPoint="0,0">
                        <LinearGradientBrush.GradientStops>
                            <GradientStop Color="Transparent"
                          Offset="0"/>
                            <GradientStop Color="Gray"
                          Offset="0.3"/>
                            <GradientStop Color="WhiteSmoke"
                          Offset="1"/>
                        </LinearGradientBrush.GradientStops>
                    </LinearGradientBrush>
                    
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
        
    </Window.Resources>
    
    <Window.InputBindings>
        <KeyBinding Key="A" Modifiers="Ctrl" Command="{Binding SelectAllCommand}" />
        <KeyBinding Key="N" Modifiers="Ctrl" Command="{Binding NewCommand}" />
        <KeyBinding Key="O" Modifiers="Ctrl" Command="{Binding OpenCommand}" />
        <KeyBinding Key="S" Modifiers="Ctrl" Command="{Binding SaveCommand}" />
        <KeyBinding Key="S" Modifiers="Ctrl+Shift" Command="{Binding SaveAsCommand}" />
        <KeyBinding Key="Z" Modifiers="Ctrl" Command="{Binding UndoCommand}" />
        <KeyBinding Key="Y" Modifiers="Ctrl" Command="{Binding RedoCommand}" />
        <KeyBinding Key="C" Modifiers="Ctrl" Command="{Binding CopyCommand}" />
        <KeyBinding Key="V" Modifiers="Ctrl" Command="{Binding PasteCommand}" />
        <KeyBinding Key="X" Modifiers="Ctrl" Command="{Binding CutCommand}" />
        
        <KeyBinding Key="Escape" Command="{Binding UnselectAllCommand}" />
        <KeyBinding Key="Delete" Command="{Binding DeleteCommand}" />
        <KeyBinding Key="Plus" Modifiers="Ctrl" Command="{Binding ZoomInCommand}" />
        <KeyBinding Key="Minus" Modifiers="Ctrl" Command="{Binding ZoomOutCommand}" /> 
    </Window.InputBindings>
    
    <Grid Background="LightGray">
        <DockPanel LastChildFill="True" MouseMove="DockPanel_MouseMove">
            <Grid DockPanel.Dock="Top" >
                
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                
                <!-- Backgraound for Menu -->
                <!--<Border BorderBrush="Gray" BorderThickness="0,0,0,1" Grid.Row="0" Grid.Column="1" Background="{StaticResource GradientHeaderBrush}" Margin="0,-17,0,0"/>-->
                <Border BorderBrush="Gray" BorderThickness="0,0,0,1" Grid.Row="0" Grid.ColumnSpan="2" Background="{StaticResource GradientHeaderBrush}" Margin="0,-17,0,0"/>
                
                <!-- Backgraound for Taskbar -->
                <Border Background="{StaticResource MainHeaderBrush}" Grid.Row="1" Grid.RowSpan="3" Grid.Column="0" Grid.ColumnSpan="2" />
                <!--{StaticResource InvertedHeaderBrush}-->

                <Image Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Grid.RowSpan="2" Height="50" HorizontalAlignment="Center" VerticalAlignment="top" Margin="0,5,0,0" Source="/VecDraw.Resources;component/Images/VecDraw.Image.Header.png" />

                <!-- Backgraound for Menu -->
                <Border BorderBrush="Gray" BorderThickness="0,0,0,0" Grid.Row="0" Grid.Column="0"  Margin="0,-17,0,0"><!--Background="{StaticResource HeaderBrush}"-->
                    <v:MenuView />
                </Border>

                <StackPanel Grid.Column="0" Grid.Row="1" Background="Transparent" Orientation="Horizontal" Height="40">

                    <!--<ctrl:ToolBarIconButton Command="cmds:MainMenuCustomCommands.NewCommand" ToolTip="New Image" Margin="0,2,0,2" MinWidth="36" Icon="{StaticResource New}" Text="New" Foreground="WhiteSmoke"/>-->
                    <ctrl:ToolBarIconButton Command="{Binding NewCommand}" ToolTip="New Image" Margin="0,2,0,2" MinWidth="36" Icon="{StaticResource New}" Text="New" Foreground="WhiteSmoke"/>
                    <ctrl:ToolBarIconButton Command="{Binding OpenCommand}" ToolTip="Open Image" Margin="0,2,0,2" MinWidth="36" Icon="{StaticResource Open}" Text="Open" Foreground="WhiteSmoke"/>
                    <ctrl:ToolBarIconButton Command="{Binding SaveCommand}" ToolTip="Save Image" Margin="0,2,0,2" MinWidth="36" Icon="{StaticResource Save}" Text="Save" Foreground="WhiteSmoke"/>
                    <ctrl:ToolBarIconButton Command="{Binding SaveAsCommand}" ToolTip="Save Image As" Margin="0,2,0,2" MinWidth="36" Icon="{StaticResource SaveAs}" Text="Save As" Foreground="WhiteSmoke" />
                    
                    <Rectangle Width="2" Fill="{StaticResource VerticalSpliterBrush}" Stroke="Transparent" StrokeThickness="0" Margin="5,3,5,3"/>

                    <ctrl:ToolBarIconButton Command="{Binding RedoCommand}" ToolTip="Redo last step" Margin="0,2,0,2" MinWidth="36" Icon="{StaticResource Redo}" Text="Redo" Foreground="WhiteSmoke"/>
                    <ctrl:ToolBarIconButton Command="{Binding UndoCommand}" ToolTip="Undo last step" Margin="0,2,0,2" MinWidth="36" Icon="{StaticResource Undo}" Text="Undo" Foreground="WhiteSmoke"/>
                        
                    <Rectangle Width="2" Fill="{StaticResource VerticalSpliterBrush}" Stroke="Transparent" StrokeThickness="0" Margin="5,3,5,3"/>

                    <ctrl:ToolBarIconButton Command="{Binding ZoomInCommand}" ToolTip="Zoom In" Margin="0,2,0,2" MinWidth="36" Icon="{StaticResource Plus}" Text="Zoom In" Foreground="WhiteSmoke"/>
                    <ctrl:ToolBarIconButton Command="{Binding ZoomOutCommand}" ToolTip="Zoom Out" Margin="0,2,0,2" MinWidth="36" Icon="{StaticResource Minus}" Text="Zoom Out" Foreground="WhiteSmoke"/>
                    
                </StackPanel>

                <v:ToolBarView Grid.Column="0" Grid.Row="2" DataContext="{Binding ElementName=canvasManager, Path=SelectedContent}"/>

                <!--<uc:CanvasSelectionPanel Grid.Column="1" Grid.Row="0" Grid.RowSpan="3" Background="Transparent" ItemsSource="{Binding ElementName=canvasManager, Path=VectorImages}" />-->
                <v:CanvasSelectionPanelView Grid.Column="1" Grid.Row="0" Grid.RowSpan="3" DataContext="{Binding ElementName=canvasManager}" HorizontalAlignment="Right" />
                <!--<v:CanvasSelectionPanelView Grid.Column="1" Grid.Row="0" Grid.RowSpan="3" DataContext="{Binding ElementName=canvasManager, Path=VectorImages}" HorizontalAlignment="Right" />-->
                <!--<uc:CanvasSelectionPanelOld Name="documentSelectionPanel" Grid.Column="2" Grid.Row="0" Grid.RowSpan="3" Background="Transparent" DocumentSelected="documentSelectionPanel_DocumentSelected" CloseCanvas="OnCloseCanvas" />-->
                
            </Grid>

            <Grid DockPanel.Dock="Bottom" Background="#101010" >
                <!--<Border Height="25" Margin="0,0,5,5" BorderBrush="#777" CornerRadius="0,4,4,0" Background="{StaticResource InvertedHeaderBrush}">
                    <StatusBar Background="Transparent" Foreground="WhiteSmoke">
                        <StatusBarItem DockPanel.Dock="Left">
                            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Name="txtStatusText1"/>
                        </StatusBarItem>
                        <Separator DockPanel.Dock="Left" />

                        <StatusBarItem DockPanel.Dock="Right">
                            <TextBlock Name="statusMousePos" Width="80" >0, 0</TextBlock>
                        </StatusBarItem>
                        <StatusBarItem DockPanel.Dock="Right">
                            <Image Source="/VecDraw.Resources;component/Images/VecDraw.Icon.MouseChart.png" Height="16" SnapsToDevicePixels="True"></Image>
                        </StatusBarItem>

                        <Separator DockPanel.Dock="Right"/>
                        <StatusBarItem DockPanel.Dock="Right">
                            <TextBlock Name="statusPageSize" Width="80">600x400</TextBlock>
                        </StatusBarItem>
                        <StatusBarItem DockPanel.Dock="Right">
                            <Image Source="/VecDraw.Resources;component/Images/VecDraw.Icon.PageSize.png" Height="16" SnapsToDevicePixels="True"></Image>
                        </StatusBarItem>

                        <Separator DockPanel.Dock="Right"/>
                        <StatusBarItem DockPanel.Dock="Left">

                        </StatusBarItem>
                    </StatusBar>
                </Border>-->
                <StatusBar Background="Transparent" Foreground="WhiteSmoke">
                    <StatusBarItem DockPanel.Dock="Right">
                        <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right" Margin="5">
                            <TextBlock Text="VecDraw" FontSize="10" />
                            <TextBlock Text="|" Margin="3,0,3,0" FontSize="10"/>
                            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding Version}" FontSize="10"/>
                        </StackPanel>
                    </StatusBarItem>

                    <StatusBarItem DockPanel.Dock="Left">
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/VecDraw.Resources;component/Images/VecDraw.Icon.PageSize.png" Height="16" SnapsToDevicePixels="True" Margin="10,0,5,0"/>
                            <TextBlock Width="80" Text="{Binding PageSize}"/>
                        </StackPanel>
                    </StatusBarItem>

                    <Separator DockPanel.Dock="Left"/>
                    
                    <StatusBarItem DockPanel.Dock="Left">
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/VecDraw.Resources;component/Images/VecDraw.Icon.MouseChart.png" Height="16" SnapsToDevicePixels="True" Margin="10,0,5,0"/>
                            <TextBlock Width="80" Text="{Binding MousePosition}"/>
                        </StackPanel>
                    </StatusBarItem>

                    <!-- This item is needed to fill the statusbar and create a space in the center -->
                    <StatusBarItem DockPanel.Dock="Right"/>
                    
                    
                </StatusBar>
            </Grid>
            <!--<core:CanvasEventProvider Grid.Column="1" Canvas="{Binding ElementName=canvasManager, Path=SelectedContent}" Focusable="True" Scope="Global">-->
            <DockPanel LastChildFill="True" >

                <Grid Background="#101010">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Grid Margin="0,5,0,5" Grid.RowSpan="2">
                        <Border BorderBrush="#484848" BorderThickness="0,0,1,0" CornerRadius="0,4,4,0" >
                            <Border.Background>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                    <GradientStop Offset="0.0" Color="#484848" />
                                    <GradientStop Offset="1.0" Color="#282828" />
                                </LinearGradientBrush>
                            </Border.Background>

                            <v:PluginPanelView DataContext="{Binding ElementName=canvasManager, Path=SelectedContent}"/>
                        </Border>
                    </Grid>

                    <core:CanvasEventProvider Grid.Column="1" Canvas="{Binding ElementName=canvasManager, Path=SelectedContent}" Focusable="True" Drop="Canvas_OnDrop" AllowDrop="True" >
                        <Border BorderBrush="#484848" Margin="5" BorderThickness="1" CornerRadius="4" Background="#D8D8D8" >
                            <!--<ScrollViewer Grid.Column="1" Margin="5" Name="scroller" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" IsTabStop="False">-->
                            <ScrollViewer Grid.Column="1" Margin="5" Name="scroller" HorizontalScrollBarVisibility="Auto" CanContentScroll="False" VerticalScrollBarVisibility="Auto" IsTabStop="False" >
                                <ScrollViewer.Resources>
                                    <ResourceDictionary>
                                        <ResourceDictionary.MergedDictionaries>
                                            <ResourceDictionary Source="/Resources/DrawingCanvasTemplates.xaml" />
                                        </ResourceDictionary.MergedDictionaries>
                                    </ResourceDictionary>
                                </ScrollViewer.Resources>
                                <document:CanvasManager DockPanel.Dock="Left" x:Name="canvasManager" Focusable="True" SelectedImage="{Binding SelectedImage, Mode=OneWayToSource}"  SelectedItem="{Binding SelectedCanvas}"
                                                CanvasChanged="canvasManager_CanvasChanged" ZoomChanged="Canvas_OnZoomChanged" MouseWheel="Canvas_OnMouseWheel" >
                                </document:CanvasManager>
                            </ScrollViewer>
                        </Border>
                    </core:CanvasEventProvider>

                    <Border BorderBrush="#484848" Grid.Row="1" Grid.Column="1" Height="100" Margin="5" BorderThickness="1" CornerRadius="4" Background="{StaticResource HeaderBrush}" >
                        <v:PropertiesView Margin="5" DataContext="{Binding ElementName=canvasManager, Path=SelectedContent}" FontSize="10" FontWeight="Heavy" Foreground="WhiteSmoke" />
                    </Border>

                </Grid>

                <!--<uc:CanvasLayoutManager>
                    <ScrollViewer Name="scroller" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" IsTabStop="False">
                        <document:CanvasManager DockPanel.Dock="Left" x:Name="canvasManager"  Focusable="True" 
                                                CanvasChanged="canvasManager_CanvasChanged"
                                                CloseCanvas="OnCloseCanvas" >
                        </document:CanvasManager>
                    </ScrollViewer>
                </uc:CanvasLayoutManager>-->

                    <!--<gd:DockingLayoutManager Name="dockingManager" RightAnchorType="ButtonAnchor" LeftAnchorType="CollapsibleAnchor" Drop="dockingManager_Drop" PreviewMouseWheel="dockingManager_MouseWheel" >
                    <ScrollViewer Name="scroller" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" IsTabStop="False">
                        <document:CanvasManager DockPanel.Dock="Left" x:Name="canvasManager"  Focusable="True" 
                                                CanvasChanged="canvasManager_CanvasChanged"
                                                CloseCanvas="OnCloseCanvas" >
                        </document:CanvasManager>
                    </ScrollViewer>
                </gd:DockingLayoutManager>-->
                </DockPanel>
            <!--</core:CanvasEventProvider>-->
        </DockPanel>
        
    </Grid>
</ctrl:WindowExt>
